home *** CD-ROM | disk | FTP | other *** search
- package URI::URL::file;
- require URI::URL::_generic;
- @ISA = qw(URI::URL::_generic);
-
- require Carp;
- require Config;
-
- my $os = $Config::Config{'osname'};
- OS: {
- $ostype = 'vms', last if $os eq 'VMS';
- $ostype = 'dos', last if $os =~ /^(?:os2|mswin32|msdos)$/i;
- $ostype = 'mac', last if $os eq "Mac";
- $ostype = 'unix'; # The default
- }
-
-
- sub _parse {
- my($self, $init) = @_;
- $self->URI::URL::_generic::_parse($init, qw(netloc path params frag));
- }
-
- *local_path = \&{$ostype . "_path"};
-
- *query = \&URI::URL::bad_method;
- *equery = \&URI::URL::bad_method;
-
- sub newlocal;
- sub unix_path;
- sub dos_path ;
- sub mac_path ;
- sub vms_path ;
- 1;
- __END__
-
- sub newlocal {
- my($class, $path) = @_;
-
- Carp::croak("Only implemented for Unix and OS/2 file systems")
- unless $ostype eq "unix" or $^O =~ /os2|mswin32/i;
-
- my $url = new URI::URL "file:";
- unless (defined $path and
- ($path =~ m:^/: or
- ($^O eq 'os2' and Cwd::sys_is_absolute($path)) or
- ($^O eq 'MSWin32' and $path =~ m<^[A-Za-z]:[\\/]|^[\\/]{2}>))) {
- require Cwd;
- my $cwd = Cwd::fastcwd();
- $cwd =~ s:/?$:/:; # force trailing slash on dir
- $path = (defined $path) ? $cwd . $path : $cwd;
- }
- $url->path($path);
- $url;
- }
-
- sub unix_path
- {
- my $self = shift;
- my @p;
- for ($self->path_components) {
- Carp::croak("Path component contains '/' or '\0'") if m|[\0/]|;
- if (@p) {
- next unless length $_; # skip empty path segments
- next if $_ eq '.'; # skip these too
- if ($_ eq '..' && $p[-1] ne '..') { # go up one level
- pop(@p) if $p[-1] ne '';
- next;
- }
- }
- push(@p, $_);
- }
- shift(@p) if @p > 1 && $p[0] eq '.'; # './' rendundant if there is more
- return '/' if !@p || (@p == 1 && $p[0] eq '');
- join('/', @p);
- }
-
- sub dos_path
- {
- my $self = shift;
- my @p;
- for ($self->path_components) {
- Carp::croak("Path component contains '/' or '\\'") if m|[/\\]|;
- push(@p, uc $_);
- }
- my $p = join("\\", @p);
- $p =~ s/^\\([A-Z]:)/$1/; # Fix drive letter specification
- $p;
- }
-
- sub mac_path
- {
- my $self = shift;
- my @p;
- for ($self->path_components) {
- Carp::croak("Path component contains ':'") if /:/;
- push(@p, $_);
- }
- if (@p && $p[0] eq '') {
- shift @p;
- } else {
- unshift(@p, '');
- }
- join(':', @p);
- }
-
- sub vms_path
- {
-
-
- my $self = shift;
- my @p = $self->path_components;
- my $abs = 0;
- if (@p && $p[0] eq '') {
- shift @p;
- $abs = 1;
- }
- my $p = '';
- $p = uc(shift(@p)) . ":" if @p && $p[0] =~ /\$/;
- my $file = pop(@p);
- $p .= "[" . join(".", map{uc($_)} @p) . "]" if @p;
- $p .= uc $file;
- $p =~ s/\[/[./ unless $abs;
- $p;
- }
-
- 1;
-